package newnes.tests;
import newnes.io.memory.*;

public class MemoryUsage {
	
	public static long calculateMemoryUsage(Memory[] hooks) 
	{ 	
			hooks = null; 
			long mem0 = Runtime.getRuntime().totalMemory(); 
			Runtime.getRuntime().freeMemory(); 
			long mem1 = Runtime.getRuntime().totalMemory(); 
			Runtime.getRuntime().freeMemory(); 
			hooks = null; 
			System.gc(); 
			System.gc(); System.gc(); 
			System.gc(); System.gc(); 
			System.gc(); System.gc(); 
			System.gc(); System.gc(); 
			System.gc(); System.gc(); 
			System.gc(); System.gc(); 
			System.gc(); System.gc(); 
			System.gc(); 
			mem0 = Runtime.getRuntime().totalMemory(); 
			Runtime.getRuntime().freeMemory();
		 	hooks = new Memory[16384]; 
		 	hooks[0] = new Rom(0x1000);
		 	System.gc(); System.gc(); 
		 	System.gc(); System.gc(); System.gc(); System.gc(); 
		 	System.gc(); System.gc(); System.gc(); System.gc(); 
		 	System.gc(); System.gc(); System.gc(); System.gc(); 
		 	System.gc(); System.gc(); 
		 	mem1 = Runtime.getRuntime().totalMemory(); 
		 	Runtime.getRuntime().freeMemory(); 
		 	return mem1 - mem0; 
	}
	/**
	 * Method main
	 *
	 *
	 * @param args
	 *
	 */
	public static void main(String[] args) {
		// TODO: Add your code here
		Memory[] hooks = null;
		long memory_usage = calculateMemoryUsage(hooks);
		System.out.println("Using " + memory_usage + " bytes");
	}	
}
